<style>
    #user-update {
        padding: 20px 25px 25px 0;
    }

    #user-update .layui-treeSelect .ztree li a, .ztree li span {
        margin: 0 0 2px 3px !important;
    }
</style>
<div class="layui-fluid" id="course-update">
    <form class="layui-form" action="" lay-filter="course-update-form">

        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label febs-form-item-require">课程ID：</label>
            <div class="layui-input-block">
                <input type="text" name="courseId" minlength="4" maxlength="10" data-th-id="${course.courseId}"
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">课程名称：</label>
            <div class="layui-input-block">
                <input type="text" name="courseName" minlength="4" maxlength="10" data-th-value="${course.courseName}"
                       lay-verify="range|username" autocomplete="off" class="layui-input" id="courseId">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">所属班级：</label>
            <div class="layui-input-block">
                <input type="text" name="deptNameList" minlength="4" maxlength="10" data-th-value="${course.deptNameList}"
                        autocomplete="off" class="layui-input" readonly>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">课程内容/大纲</label>
            <div class="layui-input-block">
                <input type="hidden" name="remark" id="remark">
                <div id="editor">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">状态：</label>
            <div class="layui-input-block">
                <input type="radio" name="state" value="1" title="有效">
                <input type="radio" name="state" value="0" title="禁用">
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="course-update-form-submit" id="submit"></button>
        </div>
    </form>
</div>
<script type="text/javascript" th:src="@{febs/lay/extends/wangEditor.min.js}"></script>
<script data-th-inline="javascript">
    layui.use(['febs', 'form', 'eleTree', 'tree','tableSelect', 'formSelects', 'validate', 'treeSelect'], function () {
        var $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            formSelects = layui.formSelects,
            treeSelect = layui.treeSelect,
            tableSelect = layui.tableSelect,
            form = layui.form,
            eleTree = layui.eleTree,
            course = [[${course}]],
            $view = $('#course-update'),
            tree = layui.tree,
            validate = layui.validate;

        form.verify(validate);
        form.render();

      /*  tableSelect.render({
            elem: '#experiment_table',	//定义输入框input对象 必填
            checkedKey: 'courseId', //表格的唯一建值，非常重要，影响到选中状态 必填
            searchKey: 'courseName',	//搜索输入框的name值 默认keyword
            searchPlaceholder: '请输入实验课程',	//搜索输入框的提示文字 默认关键词搜索
            table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                url: ctx + 'course/select/course',
                cols: [
                    [
                        { type: 'radio' },
                        {field: 'courseId', title: '课程ID', minWidth: 100},
                        {field: 'courseName', title: '课程名称', minWidth: 100},
                        {field: 'deptNameList', title: '班级名称列表', align: 'center', width: 300},
                    ]
                ]
            },
            done: function (elem, data) {
                //选择完后的回调，包含2个返回值 elem:返回之前input对象；data:表格返回的选中的数据 []
                //拿到data[]后 就按照业务需求做想做的事情啦~比如加个隐藏域放ID...
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.courseName);
                    $("#courseId").val(item.courseId);
                });
                elem.val(NEWJSON.join(","))
            }
        });
*/

        initUserValue();

        formSelects.render();

        treeSelect.render({
            elem: $view.find('#course-update-dept'),
            type: 'get',
            data: ctx + 'dept/select/tree',
            placeholder: '请选择',
            search: false,
            success: function () {
                treeSelect.checkNode('course-update-dept', course.courseId);
            }
        });


        var _deptTree = eleTree.render({
            elem: '.ele1',
            url: ctx + 'dept/tree',
            accordion: true,
            highlightCurrent: true,
            showCheckbox: true,
            checkStrictly: true,
            renderAfterExpand: false,
            /*   where: {
                   "deptName": $deptName.val().trim(),
                   "invalidate_ie_cache": new Date()
               },*/
            request: {
                name: 'name',
                key: "id",
                checked: "checked",
                data: 'data'
            },
            response: {
                statusName: "code",
                statusCode: 200,
                dataName: "data"
            },
           // defaultCheckedKeys: user.deptIds
        });

        // alert(user.deptIds);
        // _deptTree.setChecked(user.deptIds,true);

        var E = window.wangEditor;
        var editor = new E('#editor');
        editor.create();
        editor.txt.html(course.courseContent);
        function initUserValue() {
            form.val("course-update-form", {
                "courseId": course.courseId,
                "courseName": course.courseName,
                "deptNameList": course.deptNameList,
                "courseContent": course.courseContent,
                "state": course.state,
                "createTime": course.createTime,
            });
        }

        form.on('submit(course-update-form-submit)', function (data) {
            if (febs.nativeEqual(data.field, course)) {
                febs.alert.warn('数据未作任何修改！');
                return false;
            }
            febs.post(ctx + 'course/update', data.field, function () {
                layer.closeAll();

                $('#febs-course').find('#query').click();
            });
            return false;
        });
    });
</script>